CC         = gcc
#PKGS      = 
LIBNAME    = mylib
SRCDIR     = src
BUILDDIR   = build
CFLAGS     = -g -Wall -fPIC # `pkg-config --cflags $(PKGS)`
#LIBS       = `pkg-config --libs $(PKGS)`
TARGET     = lib$(LIBNAME).so
LDFLAGS    = -shared -Wl,-soname=$(TARGET)
 
SRCEXT     = c
SOURCES    = $(shell find $(SRCDIR) -type f -name *.$(SRCEXT) | grep -v unittest)
OBJECTS    = $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
DEPS       = $(OBJECTS:.o=.deps)
 
$(TARGET): $(OBJECTS)
	@echo " Linking..."; $(CC) $(LDFLAGS) $^ -o $(TARGET) # $(LIBS)
 
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
	@mkdir -p $(BUILDDIR)
	@echo " CC $<"; $(CC) $(CFLAGS) -MD -MF $(@:.o=.deps) -c -o $@ $<
 
clean:
	@echo " Cleaning..."; $(RM) -r $(BUILDDIR) $(TARGET)
 
-include $(DEPS)
 
.PHONY: clean
